#include "c10_T5_stack.h"
#include <iostream>
#include <string>

Item getitem(void);

void main()
{
	Item temp;
	std::string choice;
	double payment_s=0.0;
	
	std::cout << "create an empty stack\n";
	Stack st;

	std::cout << "Make a choice, enter push or pop (enter quit for ending):_\b";
	getline(std::cin, choice);
	while (choice != "quit")
	{
		while (choice != "push" && choice != "pop")
		{
			std::cin.clear();
			//while (std::cin.get() != '\n')
			//	continue;
			std::cout << "Bad input, Make a choice, enter push or pop :_\b";
			getline(std::cin, choice);
		}

		if (choice == "push")
		{
			if (st.isfull())
				std::cout << "stack is already full\n";
			else
			{
				temp = getitem();
				st.push(temp);
				std::cout << "the item has been pushed into stack.\n";
			}
		}

		if (choice == "pop")
		{
			if (st.isempty())
				std::cout << "stack is already empty\n";
			else
			{
				st.pop(temp);
				payment_s += temp.payment;
				std::cout << "top item has been poped out of stack. \n"
					<<"Report payments : " << payment_s << std::endl;
			}
		}
		std::cout << "Make a choice, enter push or pop (enter quit for ending):_\b";

		getline(std::cin, choice);
	}
	std::cout << "Bye!\n";
	system("pause");
}

Item getitem()
{
	Item i;
	std::cout << "enter the item informaion in order :\n"
		<< "fullname :_\b";
	getline(std::cin, i.fullname);
	std::cout << "payment :_\b";
	std::cin >> i.payment;

	std::cin.clear();
	while (std::cin.get() != '\n')
		continue;

	return i;
}
